package com.arraylist;

import java.util.ArrayList;
import java.util.Scanner;

// 菜品操作类：负责上架和浏览功能的实现
public class FoodOperator {
//  1.定义一个ArrayList集合对象，负责存储菜品对象信息

    private ArrayList<Food> foodList = new ArrayList<>();
    // foodList = []

    // 2.开发功能：上架菜品功能
    public void addFood() {
        // 3.创建一个菜品对象，封装上架菜品信息
        Food f = new Food();

        // 4.录入菜品信息进去
        Scanner sc = new Scanner(System.in);

        System.out.println("菜品名称");
        String name = sc.next();
        f.setName(name);

        System.out.println("菜品价格");
        double price = sc.nextDouble();
        f.setPrice(price);

        System.out.println("菜品描述");
        String desc = sc.next();
        f.setDesc(desc);

        // 5、把菜品对象存入到集合中去
        foodList.add(f);

        System.out.println("上架成功");
    }

    // 6.展示菜品
    // foodList = [f1,f2,f3,...]

    public void showAllFoods() {
        if (foodList.size() == 0) {
            System.out.println("没有菜品，先去上架");
        }

        for (int i = 0; i < foodList.size(); i++) {
            Food f = foodList.get(i);
            System.out.println("名字：" + f.getName());
            System.out.println("价格：" + f.getPrice());
            System.out.println("描述：" + f.getDesc());
            System.out.println("---------------------------------");
        }
    }

    // 负责展示操作页面
    public void start() {

        while (true) {

            System.out.println("请选择功能：");
            System.out.println("1.上架菜品：");
            System.out.println("2.展示菜品：");
            System.out.println("3.退出");

            Scanner sc = new Scanner(System.in);
            System.out.println("输入你的操作：");
            String command = sc.next();

            switch (command) {
                case "1":
                    addFood();
                    break;

                case "2":
                    showAllFoods();
                    break;

                case "3":
                    System.out.println("退出成功");
                    return; // 退出 start方法

                default:
                    System.out.println("输入错误");
            }
        }
    }
}
